package com.hptpd.questionnairesurvey.domain;

import com.google.common.collect.Lists;
import com.hptpd.questionnairesurvey.domain.question.BaseQuestion;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/9/11
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
@Entity
@Table(name = "questionnaire")
@Data
public class Questionnaire {
    @Id
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @GeneratedValue(generator = "uuid")
    @Column(name = "id")
    private String id;

    @Column(name = "name")
    private String name;

    @Column(name = "tag", length = 1024)
    private String tag;

    @Column(name = "state")
    private String state;

    @Column(name = "created_at")
    private Date createdAt;

    @Column(name = "deleted")
    private Boolean deleted = false;

    @OneToMany(mappedBy = "questionnaire", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private List<Survey> surveys = Lists.newArrayList();

    @OneToMany(mappedBy = "questionnaire", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private List<BaseQuestion> baseQuestions = Lists.newArrayList();

    @OneToMany(mappedBy = "questionnaire", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
    private List<Dimensionality> dimensionalities = Lists.newArrayList();
}
